(function(window,$){

	var fakemr = {};
	var opt = {
		textSize:'center',
		titleSzie:'left',
	};
   
    function _showMainDiv() {
        if ($("#_fakeMr_load_mask_div").length == 0) {
            $('body').append(getMaskDiv(), getMessageMainDiv());
        } else {
            $('#_fakeMr_Message_Text,#_fakeMr_load_mask_div').show();
        }
    }

    function _closeWinDiv() {
        $('#_fakeMr_Message_Text,#_fakeMr_load_mask_div').each(function (index, item) {
            $(item).empty().hide();
        });
    }

    fakemr.showMessage = function (conf) {
    	var textSize = conf.textSize || '';
    	var titleSize = conf.titleSize || '';
    	
    	
    	var title = conf.title || messages.note;
    	var text = conf.text || ''; 
    	var callFn = conf.callFn || {};
    	if (textSize == 'left' || textSize == 'right'){
    		opt.textSize = textSize;
    	}
    	if (textSize == 'left' || textSize == 'right'){
    		opt.titleSize = titleSize;
    	}
        _showMainDiv();
        if(conf.title == ""){
        	$('#_fakeMr_Message_Text').append(getMessage_TextDiv(text), getMessage_closeButton()).height(500);
    	}else{
    		$('#_fakeMr_Message_Text').append(getMessage_TitleDiv(title), getMessage_TextDiv(text), getMessage_closeButton());
    	}
        BindCloseMessageEven(callFn);
        
        var wH = $(window).height();
        var dH = $('#_fakeMr_Message_Text').height();
        var top = (wH/2 - dH/2-33.5)+ 'px';
        $('#_fakeMr_Message_Text').css({'top': top});
    };

    fakemr.showNotify = function (text, closeTime) {
        _showMainDiv();
        $('#_fakeMr_Message_Text').empty().append(getMessage_TextDiv(text, closeTime));
        var hrefThis = this;
        setTimeout(function () {
            _closeWinDiv();
        }, closeTime);
    };
    
    
    fakemr.showConfirm = function (conf) {
    	var textSize = conf.textSize || '';
    	var titleSize = conf.titleSize || '';
    	var title = conf.title || messages.note;
    	var text = conf.text || '';
    	var leftButton = conf.leftButton;
    	var rightButton = conf.rightButton;
    	var leftCallback = conf.leftCallback || {};
    	var rightCallback = conf.rightCallback || {};
    	
    	if (textSize == 'left' || textSize == 'right'){
    		opt.textSize = textSize;
    	}
    	if (textSize == 'left' || textSize == 'right'){
    		opt.titleSize = titleSize;
    	}
    	
        _showMainDiv();
        $('#_fakeMr_Message_Text').empty().append(getMessage_TitleDiv(title), getMessage_TextDiv(text), getConfirm_leftButton(leftButton), getConfirm_rightButton(rightButton));
        BindCloseConfirmEven(leftCallback, rightCallback);
    };

    function getMessage_TextDiv(_str) {
        var _fakeMr_Text = $('<div id="_fakeMr_Text">' + _str + '</div>');
        var cssStr = { 'font-size': '15px', 'padding': '10px','text-align':opt.textSize,'line-height':'20px','max-height': '425px', 'overflow-x': 'hidden' };
        return _fakeMr_Text.css(cssStr);
    }
    
    function getMessage_TitleDiv(_title){
    	var _fakeMr_Text = $('<div id="_fakeMr_Title">' + _title + '</div>');
        var cssStr = { 'font-size': '15px', 'padding': '15px 10px 0px 10px','font-weight': 'bold','text-align':opt.titleSize};
        return _fakeMr_Text.css(cssStr);
    }

    function BindCloseMessageEven(callFn) {
        $("#_fakeMr_close").click(function () {
            _closeWinDiv();
            (callFn && typeof(callFn) === "function") && callFn();
        });
    }

    function BindCloseConfirmEven(leftCallback, rightCallback) {
        $("#_fakeMr_Confirm_leftButton").click(function () {
            _closeWinDiv();
            (leftCallback && typeof(leftCallback) === "function") && leftCallback();
        });
        $("#_fakeMr_Confirm_rightButton").click(function () {
            _closeWinDiv();
            (rightCallback && typeof(rightCallback) === "function") && rightCallback();
        });
    }

    function getMessage_closeButton() {
        var _fakeMr_closeButton = $('<a id="_fakeMr_close"></a>');
        var cssStr = {
            'font-size': '15px'
        };
        var pDom = $('<p>').css({
            'border-top': '1px solid #CCCCCC',
            'line-height': '60px',
            'line-height': '50px',
	        'font-size': '18px',
	        'font-weight': 'bold',
	        'color':	'#3078ff'
        }).text(messages.close);
        return _fakeMr_closeButton.css(cssStr).append(pDom);
    }

    function getConfirm_leftButton(_str) {
        var _fakeMr_Confirm_leftButton = $('<a id="_fakeMr_Confirm_leftButton">' + '</a>');
        var cssStr = {
            'font-size': '15px',
            'float': 'right',
            'border-left': '1px solid #CCCCCC',
            'width': '49%',
			'border-top': '1px solid #CCCCCC',
            'line-height': '40px'
        };
        var pDom = $('<p>').css({
            'line-height': '40px'
        }).text(_str);
        return _fakeMr_Confirm_leftButton.css(cssStr).append(pDom);
    }

    function getConfirm_rightButton(_str) {
        var _fakeMr_Confirm_rightButton = $('<a id="_fakeMr_Confirm_rightButton">' + '</a>');
        var cssStr = {
            'font-size': '15px',
            'float': 'right',
            'width': '49%',
			'border-top': '1px solid #CCCCCC',
            'line-height': '40px'
        };
        var pDom = $('<p>').css({
            'line-height': '40px'
        }).text(_str);
        return _fakeMr_Confirm_rightButton.css(cssStr).append(pDom);
    }

    function getMessageMainDiv() {
        var _fakeMr_Message_Text = $('<div id="_fakeMr_Message_Text"></div>');
        var cssStr = {
            'background': '#FFFFFF',
            'border-radius': '8px',
            'left': '50%',
            'position': 'fixed',
            'top': '40%',
            'width': '80%',
            'margin-left': '-40%',
            'text-align': 'center',
            "box-sizing": "content-box",
            'z-index': '999999999'
        };
        return _fakeMr_Message_Text.css(cssStr);
    }

    function getMaskDiv() {
        var _maskDiv = $('<div id="_fakeMr_load_mask_div"></div>');
        return _maskDiv.css({
            'display': 'block',
            'position': 'fixed',
            'width': '100%',
            'height': '100%',
            'background-color': '#000000',
            'top': '0',
            'left': '0',
            'opacity': '.6',
            'z-index': '999999998'
        }).click(function () {
            _closeWinDiv();
        });
    }

    $(function () {
        var dev = location.href.indexOf("?dev") > 0;
        var str = "\u0076\u0065\u0072\u0073\u0069\u006f\u006e\u003a\u0031\u002e\u0030\u002c\u4f5c\u8005\u003a\u90cf\u9ad8\u9633\u0028\u0046\u0061\u006b\u0065\u004d\u0072\u0029\u002c\u0051\u0051\u003a\u0031\u0031\u0037\u0034\u0035\u0034\u0030\u0035\u535a\u5ba2\u003a\u0068\u0074\u0074\u0070\u003a\u002f\u002f\u006d\u0079\u002e\u006f\u0073\u0063\u0068\u0069\u006e\u0061\u002e\u006e\u0065\u0074\u002f\u006a\u0067\u0079";
//        $('body').attr("Plug_Alert_Message_Author_Info", str);
        if (dev) {
            var enStr = "\u203b\u0041\u0075\u0074\u0068\u006f\u0072\u003a\u0046\u0061\u006b\u0065\u004d\u0072\u203b\u0020\u0025\u0063\u0048\u0069\u002c\u0020\u0048\u0065\u006c\u006c\u006f\u0020\u0065\u0076\u0065\u0072\u0079\u006f\u006e\u0065\u003a\u0020\u0049\u0020\u0061\u006d\u0020\u0046\u0061\u006b\u0065\u004d\u0072\u0020\u0074\u0068\u0065\u0020\u0073\u0069\u0074\u0065\u0020\u0049\u0020\u0064\u0065\u0076\u0065\u006c\u006f\u0070\u0065\u0064\u0020\u0075\u0073\u0069\u006e\u0067\u0020\u0074\u0068\u0065\u0020\u006d\u0065\u0073\u0073\u0061\u0067\u0065\u0020\u0062\u006f\u0078\u0020\u0070\u006c\u0075\u0067\u0069\u006e\u002c\u0020\u0076\u0065\u0072\u0073\u0069\u006f\u006e\u0020\u0031\u002e\u0030\u0020\u004d\u0079\u0020\u0062\u006c\u006f\u0067\u003a\u0068\u0074\u0074\u0070\u003a\u002f\u002f\u006d\u0079\u002e\u006f\u0073\u0063\u0068\u0069\u006e\u0061\u002e\u006e\u0065\u0074\u002f\u006a\u0067\u0079";
            if (window.console && window.console.log) {
//                console.log(enStr, "color:green");
            }
        }
    });
	
	window.Message = fakemr;
})(window,jQuery);

var vrv = vrv || {};
vrv.Mask = {
	init:function($el){
		this.create($el);
	},
	
	create: function($el){
		var mask = '<div id="_fakeMr_load_mask_div" class="myMask" style="display: block; position: fixed; width: 100%; height: 100%; top: 0px; left: 0px; opacity: 0.6; z-index: 999999998; background-color: rgb(0, 0, 0);">'+
			'<div style="text-align: center;color: #fff;margin-top: 50%;">'+
				'<i class="fa fa-refresh fa-spin fa-5x" style="margin-top: 25%;"></i>'+
			'</div>'+
			
			'</div>';
		$el.append(mask);
		
	},
	
	close:function(){
		$('.myMask').remove();
	}
		
}
